// pages/enterprise/home/home.js
var app = getApp();
import {
    ajaxPost,
    showToast
}
from '../../../../utils/util.js';
import IMController from '../../../../IMJS/im'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        userId: 0,
        page: 0,
        limit: 10,
        selectVal: '1',
        noGet: false,
        listSource: []
    },
    clickSelect(e) {
        if (e.currentTarget.dataset.type !== this.data.selectVal) {
            this.setData({
                page: 0,
                noGet: false,
                selectVal: e.currentTarget.dataset.type,
            })
            this.getList(true)
        }
    },
    getList(type) {
        let _this = this;
        if (_this.data.noGet) {
            return;
        }
        let data = {
            token: wx.getStorageSync('token'),
            page: ++_this.data.page,
            limit: _this.data.limit,
            type: _this.data.selectVal,
            user_id: this.data.userId,
        };
        ajaxPost("/authuser/followmeetinglist", data, function (res) {
            if (res.code == 0) {
                let data = res.data;
                if (type) {
                    _this.setData({
                        noGet: false,
                        listSource: data,
                    })
                    return;
                }
                if (data.length == 0) {
                    _this.setData({
                        noGet: true
                    })
                } else {
                    let newarr = _this.data.listSource.concat(data)
                    _this.setData({
                        listSource: newarr,
                    })
                }
            } else {
                showToast('text', res.msg)
            }
        });
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
            userId: options.userId
        })
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        this.setData({
            page: 0,
        })
        this.getList(true)

    },

    /**
     * 去详情页
     * @param {*} e  index
     */
    goCont(e) {
        let index = e.currentTarget.dataset.index
        let data = this.data.listSource[index]
        if (data.status == 1 && this.data.selectVal == 1 && data.app_status == 2) {
            wx.navigateTo({
                url: "/pages/enterprise/enterpriseCont/enterpriseCont?id=" + data.id + '&roomid=' + data.roomid
            });
        }
        if (data.status == 2 && this.data.selectVal == 1 && data.app_status == 2) {
            showToast('text', '招聘会暂未开场，请开场后进入')
            return;
        }
        if (data.app_status != 2) {
            wx.navigateTo({
                url: `/pages/web/web?url=${app.globalData.WEBURL}/h5/index/weibaoming`
            });
            return;
        }
        if (data.status !== 3 && this.data.selectVal == 2 && data.app_status == 2) {
            let studentInfo = this.data.listSource[index]
            wx.navigateTo({
                url: "/pages/enterprise/code/code?id=" + studentInfo.id
            });
        }
    },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        this.getList()
    },
})